/**
 * jims
 */
package com.jims.master.modules.doctor.web;

import com.jims.master.common.data.StringData;
import com.jims.master.common.persistence.Page;
import com.jims.master.common.utils.StringUtils;
import com.jims.master.common.web.BaseController;
import com.jims.master.modules.doctor.entity.ClinicMaster;
import com.jims.master.modules.doctor.entity.ClinicOrders;
import com.jims.master.modules.doctor.service.ClinicOrdersService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 门诊医嘱Controller
 * @author CTQ
 * @version 2017-03-13
 */
@Controller
@RequestMapping(value = "${adminPath}/doctor/clinicOrders")
public class ClinicOrdersController extends BaseController {

	@Autowired
	private ClinicOrdersService clinicOrdersService;
	
	@ModelAttribute
	public ClinicOrders get(@RequestParam(required=false) String id) {
		ClinicOrders entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = clinicOrdersService.get(id);
		}
		if (entity == null){
			entity = new ClinicOrders();
		}
		return entity;
	}
	
	@RequiresPermissions("user")
	@RequestMapping(value = {"index", ""})
	public String list(ClinicOrders clinicOrders, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ClinicOrders> page = clinicOrdersService.findPage(new Page<ClinicOrders>(request, response), clinicOrders); 
		model.addAttribute("page", page);
		return "modules/doctor/clinicOrdersIndex";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = "form")
	public String form(ClinicOrders clinicOrders, Model model) {
		model.addAttribute("clinicOrders", clinicOrders);
		return "modules/doctor/clinicOrdersForm";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = "delete")
	@ResponseBody
	public StringData delete(ClinicOrders clinicOrders) {
	    StringData data=new StringData();
		int i=clinicOrdersService.delete(clinicOrders);
        if(i>0){
            data.setCode("success");
            data.setData("删除门诊医嘱成功");
        }else{
            data.setCode("error");
            data.setData("删除门诊医嘱失败");
        }
		return data;
	}

    /**
     * 查找clinicMaster
     * @param ordersId
     * @param model
     * @return
     */
    @RequiresPermissions("user")
    @RequestMapping(value = "findClinicMaster")
    @ResponseBody
    public ClinicMaster findClinicMaster(String ordersId, Model model) {
        return clinicOrdersService.findClinicMaster(ordersId);
    }

}